home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
050a.dms
/
050a.adf
/
TEXTS
/
chapter03.txt
< prev
next >
Wrap
Text File
|
1992-02-26
|
4KB
|
121 lines
The Absolute Beginners Guide To Amos
-------------------------------------
Chapter Three
-------------
In this chapter we will be covering variables. Before you start telling
yourself you`ll never understand variables. Let me tell you it`s not half as
complicated as it first sounds.
A variable is a letter or combination of letters and numbers that hold a
numerical value.
Read the last paragraph again slowly and try to understand it.
Here are some examples of a variable name:
A
AA
ABC
AVARIABLE
YETANOTHER
F1
F1LW4
I will explain what use variables are to us in a moment so don`t worry
why we use them for now just try and understand how they work.
To use a variable we first have to give it a name.
This can be almost anything as long as it starts with a letter and not a
number and does not contain spaces. If you want a space you can use the
underscore character _ like so:
FRED_FLINTSTONE_RULES
Another restriction is that you must not use keywords, PRINT for example is a
keyword. You can use a key word amongst other letters and numbers though for
example XPRINT5. But don't worry about keywords too much for now.
Let`s set up a variable of our own. We will call our variable F1.
We must now tell Amos what value we want F1 to hold initially.
This is quite straight forward, we use the = sign and then the value so let
us say we want F1 to hold the value of 10:
F1=10
It`s as straight forward as that. We can now change the value of F1 very
easily from within our program using the INC and DEC commands.
INC F1
This will add 1 to the current value of F1. Let`s imagine that we have a
program that counts cars that pass a motorway junction and each time a
car passes we INCrement our counter by 1. Our variable (or counter if you
like) is F1 and to start off we want F1 to equal 0 as we haven`t started
counting yet. Right, we have sat down at our imaginary computer and the first
car has passed so we have to add 1 to F1 we do this in Amos with INC, as
described earlier:
INC F1
F1 now equals 1. Let`s say we now decide to go for lunch and someone else
takes over our imaginary computer and they would like to know out of
interest how many cars you have counted. In Amos we would do this:
PRINT F1
Which will PRINT the current value of F1 on the screen, the person would see
that F1 equalled 1 and call you a lazy toe rag.
We will cover the printing of a variable in the next chapter.
DEC is the exact opposite to INC this will subtract 1 from F1 like this,
F1=1
DEC F1
PRINT F1
Do you know what the answer would be? That is right, 0.
If F1 equalled 0 and you DECremented it F1 would equal -1 (minus one).
Now if you have understood this chapter so far you may be thinking what if
I wanted to DECrement more than one off of F1 or INC more than one?
Well you could of course do this,
F1=10
DEC F1
DEC F1
DEC F1
DEC F1
This would leave F1 equalling 6, not very pretty and it`s time consuming
isn`t it? How about this:
F1=10 : REM Make our variable (or counter if you like) equal 10
F1=F1-4 : REM Make our counter equal our counter-4, F1 now equals 6
REM F1=10-4
or
F1=10
F1=F1+4 : REM F1 now equals 14
which is a lot shorter, neater and easier to understand. There is another
way using ADD var,number and ADD var,-number commands but you have enough to
cope with at the moment.
Getting back to WHY we would want a number to be represented by a letter!
The reason is it`s basically the only way to manipulate numbers. You wont
find many programs written in ANY language that do not use variables.
Check out chapter 4 in your Amos manual for more info on variables.
Now load EXAMPLE3.Amos and experiment with the INC and DEC commands.
I know the program itself is not exciting but I am trying to keep things
clear and simple. Things will hot up soon enough.
End of chapter three
^^^^^^^^^^^^^^^^^^^^